﻿using CPPEI.Coolzon.Core;
using CPPEI.Coolzon.Core.Data;
using CPPEI.Coolzon.Core.Repositories;
using CPPEI.Coolzon.Core.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CPPEI.Coolzon.ManagementCenter
{
    public partial class AddSolution : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(this.txtSolutionName.Text))
                {
                    lblHint.Text = "方案名不能为空";
                    return;
                }
                else if (string.IsNullOrWhiteSpace(this.txtSolutionCaption.Text))
                {
                    lblHint.Text = "方案说明不能为空";
                    return;
                }
                else if (string.IsNullOrWhiteSpace(this.ddlSolutionType.SelectedValue))
                {
                    lblHint.Text = "方案类型不能为空";
                    return;
                }
              
                Solution solution = new Solution();
                solution.Id = Guid.NewGuid();
                solution.Type = this.ddlSolutionType.SelectedValue;
                solution.Name = txtSolutionName.Text;
                solution.Caption = txtSolutionCaption.Text;
                solution.IsEnable = chbIsEnable.Checked;
                SolutionService service = new SolutionService();
               ServiceResult result = service.AddSolution(solution);
               if (result.IsSuccess)
                    {
                        lblHint.Text = result.Message;
                        Response.Redirect("SolutionList.aspx", false);
                    }
                    else
                    {
                        lblHint.Text = result.Message;
                    }
            }
            catch (Exception ex)
            {
                lblHint.Text = "添加失败;" + ex.Message;
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("SolutionList.aspx",false);
        }
    }
}